﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using Expect.Core.Config;

namespace Expect.Core.Test
{
    using Expect.Core.CodeGen;

    [TestClass]
    public class ConfigurationTests
    {
        [TestMethod]
        public void Config_CodegenConfig_MsTest()
        {
            string filename = "Expect.Core.Test.dll.config";
            string filecontent = null;
            using (StreamReader reader = new StreamReader(filename))
            {
                filecontent = reader.ReadToEnd();
            }

            if (string.IsNullOrEmpty(filecontent)) Assert.Fail("Configuration file not found");

            var cfg = CodeGenConfig.FromContent(filecontent);
            Assert.IsNotNull(cfg);

            Assert.AreEqual(UnitTestProviders.MsTest, cfg.Framework);

        }

        [TestMethod]
        public void Config_CodegenConfig_NUnit()
        {
            string filecontent = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><configuration>" +
                "<configSections><section name=\"expect\" type=\"Expect.Core.ExpectConfigurationSection, Expect.Core\"/></configSections>"+
                "<expect><codegen unitTestProvider=\"nunit\"/></expect>" +
                "</configuration>";
            if (string.IsNullOrEmpty(filecontent)) Assert.Fail("Configuration file not found");

            var cfg = CodeGenConfig.FromContent(filecontent);
            Assert.IsNotNull(cfg);

            Assert.AreEqual(UnitTestProviders.NUnit, cfg.Framework);

        }

        [TestMethod]
        public void Config_CodegenConfig_Default()
        {
            var cfg = CodeGenConfig.FromContent(null);
            Assert.IsNotNull(cfg);

            Assert.AreEqual(UnitTestProviders.MsTest, cfg.Framework);

        }
    }
}
